﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Small.SmortHtmlHelper.UI;

namespace Small.SmortHtmlHelper.Validate
{
   public class Validator
    {
       //必填时候提示值
        private string missMessage;

public string MissMessage
{
  get { return missMessage; }
  set { missMessage = value; }
}



       //验证无效的时候的是
        private string invalidMessage;

        public string InvalidMessage
        {
            get {
                return invalidMessage; }
            set { invalidMessage = value; }
        }

       
       //是否必填
        private bool required;

        public bool Required
        {
            get { return required; }
            set { required = value; }
        }

       //获取字段为空节点信息
        public string GetMissMessage() 
        {

            if (string.IsNullOrEmpty(missMessage)) 
            {
                return null;
            }
            return "  missingMessage=\"" + missMessage + "\"";
        }

       //值无效提示节点信息
        public string GetInvalidMessage() 
        {

            if (string.IsNullOrEmpty(invalidMessage)) 
            {
                return null;
            }
            return "  invalidMessage=\"" + invalidMessage + "\"";
        }
       //必填配置节点信息
        public string GetRequired()
        {


            if (required)
            {
                return "required:true" ;
            }
            else
            {
                return "required:false";
            
            }
        }

       //获取到提示节点信息
        public string GetMessage() 
        {
            StringBuilder builder = new StringBuilder();

            if (!String.IsNullOrEmpty(missMessage)) 
            {
                builder.Append(GetMissMessage());
            }
            if (!String.IsNullOrEmpty(GetInvalidMessage())) 
            {
                builder.Append(GetInvalidMessage());
            }

            return builder.ToString();
        }

        private bool disabled;
       //是否可见
        public bool Disabled
        {
            get { return disabled; }
            set { disabled = value; }
        }

        public string GetDisabled() 
        {
            if (disabled) 
            {
                return "disabled:true";
            }
            return null;
        }

        private string validFlag;

       /// <summary>
        /// 验证控件是否通过属性,默认为data-validFlag,如果改动请修改$('form').Valid('设置的属性值')
       /// </summary>
        public string ValidFlag
        {
            get {

                if (String.IsNullOrEmpty(validFlag)) 
                {
                    validFlag = "data-validFlag";
                }
                return validFlag;
            }
            set { validFlag = value; }
        }


        private string otherDataOptions;

       /// <summary>
       /// 其他配置选项,格式[option:1,option1:2]
       /// </summary>
        public string OtherDataOptions
        {
            get {

                if (!String.IsNullOrEmpty(otherDataOptions)) 
                {
                    var options = BaseHelper.GetHtmlAttributes(otherDataOptions);

                    StringBuilder builder = new StringBuilder();
                    foreach (var item in options)
                    {
                        builder.Append(","+item.Name + ":" + item.Value);
                    }

                    otherDataOptions = builder.ToString();
                }

                return otherDataOptions; }
            set { otherDataOptions = value; }
        }

       
    }
}
